const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader')

module.exports = {
  // mode: 'production',
  mode: 'development',

  entry: {
    xxx: './src/main.js'
  },
  output: {
    path: path.resolve('dist'), // 所有打包生成的文件都在此目录下
    filename: 'js/[name].[contenthash:8].js'
  },

  module: {
    rules: [
      // css
      {
        test: /\.css$/, // 对哪些文件进行处理
        use: [
          'vue-style-loader', // 将js中的css搞到页面中的<style>
          "css-loader"  // 将css文件内容打包到js中
        ],
      },
      // less
      {
        test: /\.less$/i,
        use: [
          'vue-style-loader',
          'css-loader',
          'less-loader',  // 将less转换为css
        ],
      },

      // es6=>es5
      {
        test: /\.js$/,
        exclude: /node_modules/, // 不处理的目录
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      // vue
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      }
    ]
  },

  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html'
    }),
    new VueLoaderPlugin()
  ],

  devServer: {
    port: 8899,
    open: true
  }
}